package com.itc.dispatch.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itc.common.core.domain.R;
import com.itc.common.core.validate.Add;
import com.itc.common.core.validate.Update;
import com.itc.dispatch.domain.SysFlowType;
import com.itc.dispatch.domain.SysTagType;
import com.itc.dispatch.domain.dto.SysFlowTypePageDto;
import com.itc.dispatch.domain.dto.SysTagTypePageDto;
import com.itc.dispatch.service.SysFlowTypeService;
import com.itc.dispatch.service.SysTagTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/sys/tag")
@Api(value = "sysTagType", tags = "标签管理模块")
public class SysTagTypeController {

    @Autowired
    private SysTagTypeService sysTagTypeService;

    /**
     * 获取全部标签类型数据
     */
    @PostMapping("/getList")
    @ApiOperation(value = "获取全部标签类型数据")
    public R<List<SysTagType>> getList(@RequestBody SysTagType sysTagType){
       return sysTagTypeService.getList(sysTagType);
    }

    /**
     * 标签类型列表数据分页获取
     */
    @PostMapping("/getPage")
    @ApiOperation(value = "标签类型列表数据分页获取")
    public R<Page<SysTagType>> getPage( @RequestBody SysTagTypePageDto pageDto){
        Page page = new Page();
        page.setCurrent(pageDto.getCurrent());
        page.setSize(pageDto.getSize());
        page.setSearchCount(true);
        return sysTagTypeService.getPage(page,pageDto);
    }

    /**
     * 标签类型更新
     */
    @PostMapping("/update")
    @ApiOperation(value = "标签类型更新")
    public R update(@RequestBody @Validated(Update.class) SysTagType sysTagType){
        return sysTagTypeService.updateOne(sysTagType);
    }

    /**
     * 标签类型删除
     */
    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "标签类型删除")
    public R delete(@PathVariable("id") Long id){
        return sysTagTypeService.delete(id);
    }

    /**
     * 标签类型新增
     */
    @PostMapping("/add")
    @ApiOperation(value = "标签类型新增")
    public R add(@RequestBody @Validated(Add.class) SysTagType sysTagType){
        return sysTagTypeService.add(sysTagType);
    }

}
